<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<%@include file="/web/header.jsp" %>
<title>员工信息</title>
</head>
<body>
	<div class="layui-collapse">
		<div class="layui-colle-item">
			<h2 class="layui-colla-title">项目信息</h2>
			<div class="layui-colla-content layui-show">
				<fieldset class="layui-elem-field layui-field-title"
					style="margin-top: 0px; padding: 5px; width: 900px">
					<legend>RUCD</legend>
					<form class="layui-form">
						<div class="layui-form-item">
							<label class="layui-form-label">项目编号</label>
							<div class="layui-form-inline">
								<input type="text" name="code" placeholder="请出入项目编号"
									autocomplete="off" class="layui-input" />
							</div>
							<label class="layui-form-label">项目名称</label>
							<div class="layui-form-inline">
								<input type="text" name="name" placeholder="请出入项目名称"
									autocomplete="off" class="layui-input" />
							</div>
							<br> <span> <input type="button"
								class="layui-btn layui-btn-sm" lay-submit lay-filter="search"
								value="查询" /> <input type="reset" value="重置"
								class="layui-btn layui-btn-sm" /> <input type="button"
								class="layui-btn layui-btn-sm" value="添加" onclick="openAdd()" />
							</span>
						</div>
						<input type="hidden" name="action" value="page" /> <input
							type="hidden" name="pageIndex" value="1" /> <input type="hidden"
							name="pageLimit" value="10" />
					</form>
				</fieldset>
			</div>
		</div>
	</div>

	<div class="layui-form">
		<table class="layui-table">
			<colgroup>
				<col width="10%">
				<col width="20%">
				<col width="20%">
				<col width="20%">
				<col width="20%">
				<col>
			</colgroup>
			<thead>
				<tr>
					<th>序号</th>
					<th>编号</th>
					<th>名称</th>
					<th>部门</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody id="user_tbody"></tbody>
		</table>
		<div id="pageInfoUser" style="text-align: right; padding-right: 30px"></div>
	</div>
	<script type="text/javascript">
		element.render();
		formSubmit('/ProjectServlet', 'submit(search)', 'json', function(data) {
			console.log(data)
			var curr = $("input[name='pageIndex']").val();
			var limit = $("input[name='pageLimit']").val();

			setPageInfo('pageInfoUser', data.count, curr, limit, function(obj,
					first) {
				$("input[name='pageIndex']").val(obj.curr);
				$("input[name='pageLimit']").val(obj.limit);
				if (!first) {
					refresh();
				}//首次不执行
			})

			var html = "";//加载表格中的数据
			$.each(data.list, function(i, dom) {
				var code = dom.code ? dom.code : '';
				var name = dom.name ? dom.name : '';
				var departmentName = dom.departmentName ?dom.departmentName:"";

				var d = {
					i : (i + 1 + (curr - 1) * limit),
					name : name,
					code : code,
					departmentName:departmentName,

				};
				html += getlaytpl('#tradd', d);
			});
			$("#user_tbody").html(html);
		});

		refresh();
		function refresh() {
			$("input[type='reset']").click();
			$("input[value='查询']").click();
		}
		function openUpd(code) {
			//	openLayer('/DepartmentServlet?action=get2&code='+code,refresh)//请求转发
			openLayer('/web/page/project/update.jsp?code=' + code, refresh)
		}
		function openAdd() {
			openLayer('/web/page/project/add.jsp', refresh);
		}
		function openDepart(code){
			openLayer('/web/page/project/updDepart.jsp?code=' + code, refresh)
		}
		function resetPass(code) {
			ajax('/ProjectServlet', {
				action : 'resetPass',
				code : code
			}, 'text', function(data) {
				if (data == 1) {
					layer.msg('密码重置成功')
					//	$("inout[name='pageIndex']").val(1)
				} else {
					layer.msg('密码重置失败')
				}
			})
		}

		function del(code) {
			openConfirm(function(index) {
				ajax('/ProjectServlet', {
					action : 'del',
					code : code
				}, 'text', function(data) {
					if (data == 1) {
						refresh();
						layer.msg('删除成功')
						//	$("inout[name='pageIndex']").val(1)
					} else if (data == 0) {
						layer.msg('删除成功')
					} else if (data == 2) {
						layer.msg('删除失败--data=2')
					} else {
						layer.msg('删除失败')
					}
				})
			})
		}
	</script>

	<script id="tradd" type="text/html">
<tr>
<td>{{ d.i }}</td><td>{{ d.code }}</td><td>{{ d.name }}</td>
<td>{{ d.departmentName }}</td>
<td>
    <input type="button" value='更新' class='layui-btn layui-btn-sm' onclick='openUpd("{{ d.code }}")'/>&nbsp;
    <a href="javascript:del('{{ d.code }}');" class="layui-btn layui-btn-xs layui-btn-danger">
    <i class="layui-icon layui-icon-delete"></i></a>&nbsp;
<input type="button" value='选择部门' class='layui-btn layui-btn-sm' onclick='openDepart("{{ d.code }}")'/>&nbsp;
</td>
</tr>
</script>
</body>
</html>